#include "SPVector3.h"
#include <cmath>

namespace SP
{
	SPVector3::SPVector3(void)
	{
	}

	SPVector3::SPVector3(float x, float y, float z)
		:x(x), y(y), z(z)
	{
	}

	SPVector3::~SPVector3(void)
	{
	}

	SPVector3 SPVector3::cross(const SPVector3& vec3) const
	{
		SPVector3 result;

		result.x = y * vec3.z - z * vec3.y;
		result.y = z * vec3.x - x * vec3.z;
		result.z = x * vec3.y - y * vec3.x;

		return result;
	}

	SPVector3 operator-(const SPVector3& leftVector, const SPVector3& rightVector)
	{
		SPVector3 result;

		result.x = leftVector.x - rightVector.x;
		result.y = leftVector.y - rightVector.y;
		result.z = leftVector.z - rightVector.z;

		return result;
	}

	SPVector3& SPVector3::normalize()
	{
		float m = sqrt(x * x + y * y + z * z);

		x /= m;
		y /= m;
		z /= m;

		return *this;
	}
}
